user_edit.tpl:
	{{extends file="admin/admin_header.tpl"}}
	{{block name="content"}}
	<h3>
		<!--根据Method的内容控制标题 -->
		{{if $Method=='add'}}添加新用户{{else}}编辑用户{{/if}}
		<div class="pull-right">
			<a href="{{site_url('user/index')}}" class="btn btn-sm btn-default">返回用户列表</a>
		</div>
	</h3>
	<ul class="nav nav-tabs">
		<li class="active">
			<a href="#tab-general" style="background-color: #f8f8f8 !important;">用户信息</a>
		</li>
	</ul>
	<form action="{{site_url("user/store")}}" method="post" class="form-horizontal" autocomplete="off" style="background:#f8f8f8;padding:1em;border:1px solid #ddd;border-top:0;">
		<input type="hidden" name="Method" value="{{$Method}}">
		<input type="hidden" name="Id" value="{{$user.0.Id}}">
		<div class="tab-content">
			<div class="tab-pane active" id="tab-general" style="margin: 0 20px;">
				<div class="form-group">
					<label for="name">用户身份</label>
					<select name="Type" class="form-control">
						<option value="普通管理员" {{IsSelected("普通管理员",$user.0.Type)}}>普通管理员</option>
						<option value="超级管理员" {{IsSelected("超级管理员",$user.0.Type)}} >超级管理员</option>
					</select>
				</div>
				{{if $user_now=="超级管理员"}}
				<div class="form-group">
					<label for="name" style="display:block;">负责栏目</label>
					<span>导航模块：</span>
					<input type="checkbox" name="permission[]"  value="11" {{isChecked(11,$user.0.permission)}}/>热点新闻
					<input type="checkbox" name="permission[]"  value="2" {{isChecked(2,$user.0.permission)}}/>学院概况
					<input type="checkbox" name="permission[]"  value="3" {{isChecked(3,$user.0.permission)}}/>师资队伍
					<input type="checkbox" name="permission[]"  value="4" {{isChecked(4,$user.0.permission)}}/>科学研究
					<input type="checkbox" name="permission[]"  value="5" {{isChecked(5,$user.0.permission)}}/>人才培养
					<input type="checkbox" name="permission[]"  value="6" {{isChecked(6,$user.0.permission)}}/>国际交流
					<input type="checkbox" name="permission[]"  value="7" {{isChecked(7,$user.0.permission)}}/>学生工作
					<input type="checkbox" name="permission[]"  value="8" {{isChecked(8,$user.0.permission)}}/>招生就业
					<input type="checkbox" name="permission[]"  value="99" {{isChecked(99,$user.0.permission)}}/>党群工作
					<input type="checkbox" name="permission[]"  value="9" {{isChecked(9,$user.0.permission)}}/>院企合作
					</br>
					<span>新闻模块：</span>
					<input type="checkbox" name="permission[]"  value="12" {{isChecked(12,$user.0.permission)}}/>学院办公室
					<input type="checkbox" name="permission[]"  value="16" {{isChecked(16,$user.0.permission)}}/>科学研究
					<input type="checkbox" name="permission[]"  value="109" {{isChecked(109,$user.0.permission)}}/>人事人才
					<input type="checkbox" name="permission[]"  value="13" {{isChecked(13,$user.0.permission)}}/>国际合作
					<input type="checkbox" name="permission[]"  value="14" {{isChecked(14,$user.0.permission)}}/>本科生教育
					<input type="checkbox" name="permission[]"  value="15" {{isChecked(15,$user.0.permission)}}/>研究生教育
					<input type="checkbox" name="permission[]"  value="17" {{isChecked(17,$user.0.permission)}}/>学生事务
					<input type="checkbox" name="permission[]"  value="18" {{isChecked(18,$user.0.permission)}}/>继续教育
				</div>
				{{/if}}
				<!-- NoAccess 控制密码修改权限-->
				<div class="form-group">
					<label for="name">用户名称</label>
					<input type="text" name="UserName" class="form-control" value="{{$user.0.UserName}}" {{NoAccess($Method,'edit',$user.0.Id,$Id_now)}} />
				</div>
				<div class="form-group">
					<label for="name">用户密码</label>
					<input type="password" name="Password" class="form-control" {{NoAccess($Method,'edit',$user.0.Id,$Id_now)}} />
				</div>
			</div>
		</div>
		<div class="control-group">
			<div class="controls">
				<button type="reset" class="btn btn-default">清空</button>
				<button type="submit" class="btn btn-success">提交</button>
			</div>
		</div>
	</form>
	{{/block}}


Function.php:
	/**
	 * 根据Method和Id控制用户编辑中的用户名和密码设置权限
	 */
	function NoAccess($Method,$Method_target,$Id,$Id_target){
		if ($Method == $Method_target && $Id != $Id_target)
			return 'disabled="disabled"';
		else return '';
	}


user.php:
	/**
	 * 添加新用户动作
	 */
	function store(){
		$data=array(
			'Type'=>LfRequest::JudgeRequst('Type'),
			'permission'=>json_encode(@$_POST['permission']),
			'UserName'=> LfRequest::JudgeRequst('UserName'),
			'Password'=> md5(LfRequest::JudgeRequst('Password'))
			);
		$salt="$".LfDealString::GenerateStr()."$";
		$data['salt']=$salt;
		$Method=LfRequest::JudgeRequst('Method');
		if($Method=='add'){		
			$res=$this->db->insert('adminuser',$data);
			if($res){
				$_SESSION['info']='用户添加成功';
				ilog($_SESSION['UserName'].'添加了用户'.$data['UserName']);
				redirect('user/index');
			}else{
				die('未知错误，请重试');
			}
		}
		if($Method=='edit'){
			$Id=LfRequest::inNum('Id');
			$res=$this->db->where('Id',$Id)->update('adminuser',$data);
			if($res){
				$_SESSION['info']='用户信息修改成功';
				ilog($_SESSION['UserName'].'修改了Id为'.$Id.'的用户名:'.$data['UserName']);
				redirect('user/index');
			}else{
				die('未知错误，请重试');
			}
		}
	}
